package com.mzj.saas.admin;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.Notice;
import com.haixiaoke.saas.repository.service.INoticeService;
import com.mzj.saas.util.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公众号通知Controller
 *
 * @author qixi
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/admin/notice")
public class AdminOpNoticeController extends BaseController {
    @Autowired
    private INoticeService noticeService;


    @Autowired
    private LoginUserUtil loginUserUtil;

    /**
     * 查询公众号通知列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Notice notice) {
        startPage();
        notice.setOrgId(loginUserUtil.getOrgId());
        List<Notice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 导出公众号通知列表
     */
    //
    // @PostMapping("/export")
    // public void export(HttpServletResponse response, Notice notice) {
    //     List<Notice> list = noticeService.selectNoticeList(notice);
    //     ExcelUtil<Notice> util = new ExcelUtil<Notice>(Notice.class);
    //     util.exportExcel(response, list, "公众号通知数据");
    // }

    /**
     * 获取公众号通知详细信息
     */
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Long noticeId) {
        return success(noticeService.selectNoticeByNoticeId(noticeId));
    }

    /**
     * 新增公众号通知
     */
    @PostMapping
    public AjaxResult add(@RequestBody Notice notice) {
        notice.setOrgId(loginUserUtil.getOrgId());
        notice.setCreateBy(loginUserUtil.getId());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改公众号通知
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Notice notice) {
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除公众号通知
     */
	@DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds) {
        return toAjax(noticeService.deleteNoticeByNoticeIds(noticeIds));
    }
}
